package com.hgm.study.ui.screens

import androidx.annotation.DrawableRes
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.Divider
import androidx.compose.material.Icon
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.hgm.study.R
import com.hgm.study.ui.components.TopAppBar

/**
 * @author    HGM
 * @version   1.0
 */
@Composable
fun MineScreen() {

      val menus = listOf(
            MenuItem("学习积分"),
            MenuItem("浏览记录"),
            MenuItem("学习档案"),
            MenuItem("常见问题"),
            MenuItem("版本信息"),
            MenuItem("个人设置"),
            MenuItem("联系我们")
      )


      Column(modifier = Modifier) {
            TopAppBar {
                  Text(text = "我的", fontSize = 18.sp, color = Color.White)
            }

            LazyColumn() {
                  //头像
                  item {
                        Row(
                              modifier = Modifier.padding(16.dp),
                              verticalAlignment = Alignment.CenterVertically
                        ) {
                              Image(
                                    painter = painterResource(id = R.drawable.head),
                                    contentDescription = null,
                                    modifier = Modifier
                                          .size(62.dp)
                                          .clip(CircleShape)
                              )
                              Column(modifier = Modifier.padding(start = 12.dp)) {
                                    Text(text = "未登录", fontSize = 18.sp, color = Color(0xFF333333))
                                    Text(
                                          text = "已经坚持学习236天",
                                          fontSize = 14.sp,
                                          color = Color(0xFF999999),
                                          modifier = Modifier.padding(top = 4.dp)
                                    )
                              }
                        }
                  }

                  //菜单列表
                  itemsIndexed(menus) { index, menu ->
                        if (index == 3) {
                              Spacer(
                                    modifier = Modifier
                                          .height(24.dp)
                              )
                        }
                        Column(modifier = Modifier.fillMaxWidth().clickable {  }) {
                              Row(
                                    modifier = Modifier
                                          .fillMaxWidth()
                                          .padding(12.dp),
                                    verticalAlignment = Alignment.CenterVertically
                              ) {
                                    Text(
                                          text = menu.title,
                                          color = Color(0xFF333333),
                                          fontSize = 16.sp,
                                          modifier = Modifier.weight(1f)
                                    )
                                    Icon(
                                          imageVector = Icons.Default.ArrowForwardIos,
                                          contentDescription = null,
                                          modifier = Modifier.size(20.dp),
                                          tint = Color.Gray
                                    )
                              }
                              Divider()
                        }
                  }
            }
      }
}

//data class MenuItem(@DrawableRes val icon: Int, val title: String)
data class MenuItem(val title: String)
